package com.wang.thread;

public class ThreadNode {
    private TaskChannel taskChannel;

    public void start() {
        (new Thread(() -> {
            try {
                // 不断循环获取任务并执行
                Runnable runnable;
                while ((runnable = taskChannel.get()) != null) {
                    try {
                        runnable.run();
                    } catch (Throwable e) {
                        e.printStackTrace();
                    }
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        })).start();
    }

    public void setTaskChannel(TaskChannel taskChannel) {
        this.taskChannel = taskChannel;
    }
}
